package edu.ynu.se.xiecheng.achitectureclass.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@Where(clause = "is_deleted = 0")
public class Device extends LogicEntity {

    @Id
    private Long id;

    @Column
    private String deviceName;
    @Column
    private String deviceNumber;
    @Column
    private String deviceType;
    @Column
    private String deviceUnit;
    @Column
    private String deviceAddress;

    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties(value = {"devices"})
    private Greenhouse greenhouse;
    @OneToMany(mappedBy = "device",
            fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties("device")
    private Set<Statistic> statistics;

    public void addStatistic(Statistic statistic) {
        statistics.add(statistic);
        statistic.setDevice(this);
    }

}
